<?php

namespace app\api\server;

use app\api\server\Goods as ServerGoods;
use app\common\controller\Server;
use app\common\library\Auth;
use app\common\model\Cart as ModelCart;
use app\common\model\goods\Goods;
use app\common\model\performance\Log;
use app\common\model\User;
use DateTime;

/**
 * 分销推广逻辑
 */
class Promotion
{
    protected $auth;
    public function __construct($file = null)
    {
        $this->auth = Auth::instance();
    }
    public function team_yj()
    {

        $years = Log::where('user_id', $this->auth->id)->field("FROM_UNIXTIME(createtime,'%Y') as year,sum(num) as goods_num,sum(performance) as total_performance")->group('year')->order('year desc')->select();
        foreach ($years as $k => $v) {
            $v['month'] = Log::where('user_id', $this->auth->id)->whereTime('createtime', 'between', [$v['year'] . '-1-1', ($v['year'] + 1) . '-1-1'])->field("FROM_UNIXTIME(createtime,'%Y-%m') as month,sum(num) as goods_num,sum(performance) as total_performance")->group('month')->order('month desc')->select();
        }
        return $years;
    }
}
